package com.nbsaas.boot.scm.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.math.BigDecimal;
import java.util.Date;

@CreateByUser
@ComposeView
@Data
@FormAnnotation(title = "采购合同", model = "采购合同")
@Entity
@Table(name = "bs_purchase_contract")
@Comment("采购合同表")
public class PurchaseContract extends AbstractEntity {

    @Comment("合同编号")
    @SearchItem(name = "contractNo", key = "contractNo", label = "合同编号")
    @FormField(title = "合同编号", sortNum = "1", grid = true, required = true)
    @Column(length = 50, nullable = false, unique = true)
    private String contractNo;

    @Comment("合同标题")
    @SearchItem(name = "title", key = "title", label = "合同标题")
    @FormField(title = "合同标题", sortNum = "2", grid = true, required = true)
    @Column(length = 200, nullable = false)
    private String title;

    @Comment("供应商ID")
    @FormField(title = "供应商", sortNum = "3", grid = true, type = InputType.select, required = true)
    private Long supplierId;

    @Comment("供应商编码")
    @FormField(title = "供应商编码", sortNum = "4", grid = true)
    @Column(length = 50)
    private String supplierCode;

    @Comment("供应商名称")
    @FormField(title = "供应商名称", sortNum = "5", grid = true)
    @Column(length = 200)
    private String supplierName;

    @Comment("合同类型")
    @FormField(title = "合同类型", sortNum = "6", grid = true, type = InputType.select)
    @Column(length = 50)
    private String contractType; // FRAMEWORK-框架合同, SPECIFIC-具体合同, LONG_TERM-长期合同, SHORT_TERM-短期合同

    @Comment("合同状态")
    @FormField(title = "合同状态", sortNum = "7", grid = true, type = InputType.select)
    @Column(length = 20)
    private String contractStatus; // DRAFT-草稿, NEGOTIATING-谈判中, SIGNED-已签署, EXECUTING-执行中, COMPLETED-已完成, TERMINATED-已终止

    @Comment("审批状态")
    @FormField(title = "审批状态", sortNum = "8", grid = true, type = InputType.select)
    @Column(length = 20)
    private String approvalStatus; // PENDING-待审批, APPROVED-已审批, REJECTED-已拒绝

    @Comment("合同签订日期")
    @FormField(title = "合同签订日期", sortNum = "9", type = InputType.date, grid = true)
    private Date signingDate;

    @Comment("合同生效日期")
    @FormField(title = "合同生效日期", sortNum = "10", type = InputType.date, grid = true, required = true)
    private Date effectiveDate;

    @Comment("合同到期日期")
    @FormField(title = "合同到期日期", sortNum = "11", type = InputType.date, grid = true, required = true)
    private Date expiryDate;

    @Comment("合同总金额")
    @FormField(title = "合同总金额", sortNum = "12", grid = true, type = InputType.el_input_number, sort = true)
    @Column(precision = 15, scale = 2)
    private BigDecimal totalAmount;

    @Comment("已执行金额")
    @FormField(title = "已执行金额", sortNum = "13", grid = true, type = InputType.el_input_number)
    @Column(precision = 15, scale = 2)
    private BigDecimal executedAmount;

    @Comment("未执行金额")
    @FormField(title = "未执行金额", sortNum = "14", grid = true, type = InputType.el_input_number)
    @Column(precision = 15, scale = 2)
    private BigDecimal unexecutedAmount;

    @Comment("付款条件")
    @FormField(title = "付款条件", sortNum = "15", grid = true)
    @Column(length = 500)
    private String paymentTerms;

    @Comment("交货条件")
    @FormField(title = "交货条件", sortNum = "16", grid = true)
    @Column(length = 500)
    private String deliveryTerms;

    @Comment("质量要求")
    @FormField(title = "质量要求", sortNum = "17", type = InputType.textarea)
    @Column(columnDefinition = "text")
    private String qualityRequirements;

    @Comment("违约责任")
    @FormField(title = "违约责任", sortNum = "18", type = InputType.textarea)
    @Column(columnDefinition = "text")
    private String breachLiability;

    @Comment("争议解决")
    @FormField(title = "争议解决", sortNum = "19", type = InputType.textarea)
    @Column(columnDefinition = "text")
    private String disputeResolution;

    @Comment("合同文件")
    @FormField(title = "合同文件", sortNum = "20", type = InputType.image)
    @Column(length = 500)
    private String contractFile;

    @Comment("合同扫描件")
    @FormField(title = "合同扫描件", sortNum = "21", type = InputType.image)
    @Column(length = 500)
    private String contractScan;

    @Comment("审批意见")
    @FormField(title = "审批意见", sortNum = "22", type = InputType.textarea)
    @Column(columnDefinition = "text")
    private String approvalComment;

    @Comment("审批人ID")
    @FormField(title = "审批人", sortNum = "23", grid = true, type = InputType.select)
    private Long approverId;

    @Comment("审批人姓名")
    @FormField(title = "审批人姓名", sortNum = "24", grid = true)
    @Column(length = 100)
    private String approverName;

    @Comment("审批时间")
    @FormField(title = "审批时间", sortNum = "25", type = InputType.date, grid = true)
    private Date approvalTime;

    @Comment("备注")
    @FormField(title = "备注", sortNum = "26", type = InputType.textarea)
    @Column(columnDefinition = "text")
    private String remark;
} 